package com.hiultra.archive.service.impl;

import com.hiultra.archive.domain.ArcFamily;
import com.hiultra.archive.mapper.ArcFamilyMapper;
import com.hiultra.archive.service.IArcFamilyService;
import com.hiultra.common.constant.UserConstants;
import com.hiultra.common.core.domain.entity.SysDept;
import com.hiultra.common.utils.DateUtils;
import com.hiultra.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 全宗Service业务层处理
 * 
 * @author ls
 * @date 2022-07-28
 */
@Service
public class ArcFamilyServiceImpl implements IArcFamilyService
{
    @Autowired
    private ArcFamilyMapper arcFamilyMapper;

    /**
     * 查询全宗
     * 
     * @param familyId 全宗主键
     * @return 全宗
     */
    @Override
    public ArcFamily selectArcFamilyByFamilyId(Long familyId)
    {
        return arcFamilyMapper.selectArcFamilyByFamilyId(familyId);
    }

    /**
     * 查询全宗列表
     * 
     * @param arcFamily 全宗
     * @return 全宗
     */
    @Override
    public List<ArcFamily> selectArcFamilyList(ArcFamily arcFamily)
    {
        return arcFamilyMapper.selectArcFamilyList(arcFamily);
    }

    /**
     * 新增全宗
     * 
     * @param arcFamily 全宗
     * @return 结果
     */
    @Override
    public int insertArcFamily(ArcFamily arcFamily)
    {
        return arcFamilyMapper.insertArcFamily(arcFamily);
    }

    /**
     * 修改全宗
     * 
     * @param arcFamily 全宗
     * @return 结果
     */
    @Override
    public int updateArcFamily(ArcFamily arcFamily)
    {
        arcFamily.setUpdateTime(DateUtils.getNowDate());
        return arcFamilyMapper.updateArcFamily(arcFamily);
    }

    /**
     * 批量删除全宗
     * 
     * @param familyIds 需要删除的全宗主键
     * @return 结果
     */
    @Override
    public int deleteArcFamilyByFamilyIds(Long[] familyIds)
    {
        return arcFamilyMapper.deleteArcFamilyByFamilyIds(familyIds);
    }

    /**
     * 删除全宗信息
     * 
     * @param familyId 全宗主键
     * @return 结果
     */
    @Override
    public int deleteArcFamilyByFamilyId(Long familyId)
    {
        return arcFamilyMapper.deleteArcFamilyByFamilyId(familyId);
    }

    /**
     * 校验全宗号是否唯一
     *
     * @param arcFamily 全宗
     * @return 结果
     */
    @Override
    public String checkFamilyCodeUnique(ArcFamily arcFamily){
        Long familyId = StringUtils.isNull(arcFamily.getFamilyId()) ? -1L : arcFamily.getFamilyId();
        ArcFamily info = arcFamilyMapper.checkFamilyCodeUnique(arcFamily);
        if (StringUtils.isNotNull(info) && info.getFamilyId().longValue() != familyId.longValue())
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }

    /**
     * 校验全宗名称是否唯一
     *
     * @param arcFamily 全宗
     * @return 结果
     */
    @Override
    public String checkFamilyNameUnique(ArcFamily arcFamily){
        Long familyId = StringUtils.isNull(arcFamily.getFamilyId()) ? -1L : arcFamily.getFamilyId();
        ArcFamily info = arcFamilyMapper.checkFamilyNameUnique(arcFamily);
        if (StringUtils.isNotNull(info) && info.getFamilyId().longValue() != familyId.longValue())
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }
}
